package main

import (
	"fmt"
	"math/rand"
	"time"
)


/**
 * 测试条件
 */
func main() {

	fmt.Printf("当前时间为：%v \n", time.Now())
	
	//随机数
	r := rand.New(rand.NewSource(time.Now().UnixNano()))

	var i int = r.Intn(5)

	testIf(i)

	testSwitch(i)

	fmt.Printf("测试select \n")
	testSelect()
}


func testIf(i int){
	if i > 5 {
		fmt.Printf("你好 %v", i)
	} else {
		fmt.Printf("不好 %v", i)
	}
}


func testSwitch(i int){

	fmt.Println()

	switch i {
	case 1:
		fmt.Printf("i is %v \n", i)
	case 2:
		fmt.Printf("i is %v \n", i)
	case 3:
		fmt.Printf("i is %v \n", i)
	case 4:
		fmt.Printf("i is %v \n", i)
	default: 
		fmt.Printf("default ")
	}
}


func testSelect(){   
   
	var c1, c2, c3 chan int
	var i1, i2 int
	select {
		case i1 = <-c1:
			fmt.Printf("received %v", i1, " from c1\n")
		case c2 <- i2:
			fmt.Printf("sent ", i2, " to c2\n")
		case i3, ok := (<-c3):  // same as: i3, ok := <-c3
			if ok {
				fmt.Printf("received ", i3, " from c3\n")
			} else {
				fmt.Printf("c3 is closed\n")
			}
		default:
			fmt.Printf("no communication\n")
	}   
}